package com.example.xiaomaotv.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.example.xiaomaotv.R;
import com.example.xiaomaotv.entity.TvList;

import java.util.List;


public class ListAdapter extends ArrayAdapter<TvList> {
    private int resourceId;
    private List<TvList> tvData;
    public ListAdapter(@NonNull Context context, int resource, @NonNull List<TvList> objects) {
        super(context, resource, objects);
        resourceId = resource;
        tvData = objects;

    }

    @NonNull
    public View getView(int position, View convertView, @NonNull ViewGroup parent) {
        TvList list = getItem(position);
        View listView = LayoutInflater.from(getContext()).inflate(resourceId,null);
        TextView listName = listView.findViewById(R.id.list_name);
        TextView listTime = listView.findViewById(R.id.list_time);
        TextView listBrief = listView.findViewById(R.id.list_brief_x);
        ImageView listImage = listView.findViewById(R.id.list_img);
        listName.setText(list.getName());
        listTime.setText(list.getTime());
        listBrief.setText(list.getBrief());
        listImage.setImageResource(list.getImg());
        return listView;
    }
}
